home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT53.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  8.5 KB  |  305 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                 Demonstration Program 53                          
  5.                                           
  6.  VESA demonstration file. Any program which uses the WGT VESA library        
  7.  requires the existence of a VESA driver. Most video card manufacturers      
  8.  include software drivers with their installation diskettes. You can also    
  9.  find drivers for most popular cards on a BBS.                               
  10.                                           
  11.  VESA calls perform the same functions as their 320*200 equivalents in WGT.  
  12.                                           
  13.  *** PROJECT ***                                                             
  14.  This program requires the WGT5_WC.LIB and WVESA_WC.LIB files to be linked.  
  15.                                           
  16.  *** DATA FILES ***                                                          
  17.  WGT1.PCX and WGT2.PCX must be in your executable directory.      
  18.                                WATCOM C++ VERSION 
  19. ==============================================================================
  20. */
  21.  
  22. #include <graph.h>
  23. #include <wgt5.h>
  24. #include <wgtvesa.h>
  25.  
  26. block wgt;                    /* Pointer to our first image to load */
  27. block wgt2;                   /* Pointer to our second image to load */
  28. block ptr;                    /* Temporary pointer */
  29. color pal[256];               /* Our color palette */
  30. int videomode[10];            /* Array to hold supported modes */
  31. int totalmodes;               /* Total number of supported VESA modes */
  32.  
  33. char vstring[7][18] = { "640  x 350  x 256",
  34.             "640  x 400  x 256", "640  x 480  x 256", 
  35.             "800  x 600  x 256", "1024 x 768  x 256", 
  36.             "1280 x 1024 x 256", "1600 x 1200 x 256" };
  37.  
  38.  
  39.  
  40. void getmodes (void)
  41. {
  42.   totalmodes = 0;               /* Start counter at 0 modes supported */
  43.  
  44.   /* Now find supported modes and add them to our array */
  45.   if (wvesa_supported (V640x350))
  46.   {
  47.     videomode[totalmodes] = V640x350;
  48.     totalmodes++;
  49.   }
  50.   if (wvesa_supported (V640x400))
  51.   {
  52.     videomode[totalmodes] = V640x400;
  53.     totalmodes++;
  54.   }
  55.   if (wvesa_supported (V640x480))
  56.   {
  57.     videomode[totalmodes] = V640x480;
  58.     totalmodes++;
  59.   }
  60.   if (wvesa_supported (V800x600))
  61.   {
  62.     videomode[totalmodes] = V800x600;
  63.     totalmodes++;
  64.   }
  65.   if (wvesa_supported (V1024x768))
  66.   {
  67.     videomode[totalmodes] = V1024x768;
  68.     totalmodes++;
  69.   }
  70.   if (wvesa_supported (V1280x1024))
  71.   {
  72.     videomode[totalmodes] = V1280x1024;
  73.     totalmodes++;
  74.   }
  75.   if (wvesa_supported (V1600x1200))
  76.   {
  77.     videomode[totalmodes] = V1600x1200;
  78.     totalmodes++;
  79.   }
  80. }
  81.  
  82.  
  83. int which_string (int mode)
  84. {
  85.   /* This function simply returns a string number to display based on the
  86.      highlighted video mode */
  87.   switch (mode)
  88.   {
  89.     case V640x350   : return 0; 
  90.     case V640x400   : return 1; 
  91.     case V640x480   : return 2; 
  92.     case V800x600   : return 3; 
  93.     case V1024x768  : return 4; 
  94.     case V1280x1024 : return 5; 
  95.     case V1600x1200 : return 6; 
  96.   }
  97.   return 0;
  98. }
  99.  
  100.  
  101. int select_mode (void)
  102. {
  103.   int ctr;
  104.   int done;
  105.   int selected;
  106.   struct rccoord endy;
  107.   char ch;
  108.  
  109.   printf ("\nPress ENTER to selected highlighted mode, any other key advances highlight.\n");
  110.  
  111.   for (ctr = 0; ctr < totalmodes; ctr++)        /* Show supported modes */
  112.   {
  113.     _settextposition (13 + ctr, 1);
  114.     _outtext (vstring[ which_string (videomode[ctr]) ]);
  115.   }
  116.   endy = _gettextposition ();
  117.  
  118.   selected = 0;
  119.   done = 0;
  120.   while (!done)
  121.   {
  122.     _settextcolor (12);                       /* Highlight string */
  123.     _settextposition (13 + selected, 1);
  124.     _outtext (vstring[ which_string (videomode[selected]) ]);
  125.     ch = getch ();
  126.     if (ch == 13)                               /* Abort when ENTER pressed */
  127.       done = 1;
  128.     else {
  129.       while (kbhit ()) getch ();  
  130.       _settextcolor (7);                    /* De-highlight previous */
  131.       _settextposition (13 + selected, 1);
  132.       _outtext (vstring[ which_string (videomode[selected]) ]);
  133.       selected++;
  134.       if (selected >= totalmodes)               /* Wrap around list */
  135.     selected = 0;
  136.     }
  137.   }
  138.   _settextposition (endy.row + 1, 1);
  139.  
  140.   return videomode[selected];           /* Return the selected mode */
  141. }
  142.  
  143.  
  144. void do_pixels (void)
  145. {
  146.   while (!kbhit ())              /* Random pixels */
  147.   {
  148.     wsetcolor (rand() % 256);
  149.     wvesa_putpixel (rand() % VESAmode.XResolution, rand() % VESAmode.YResolution);
  150.   }
  151.   getch ();
  152. }
  153.  
  154.  
  155. void do_lines (void)
  156. {
  157.   while (!kbhit ())              /* Random lines */
  158.   {
  159.     wsetcolor (rand () % 256);
  160.     wvesa_line (0, 0, rand () % VESAmode.XResolution, rand () % VESAmode.YResolution);
  161.   }
  162.   getch ();
  163. }
  164.  
  165.  
  166. void do_bars (void)
  167. {
  168.   while (!kbhit ())              /* Random bars */
  169.   {
  170.     wsetcolor (rand () % 256);
  171.     wvesa_bar (rand () % VESAmode.XResolution, rand () % VESAmode.YResolution, 
  172.            rand () % VESAmode.XResolution, rand () % VESAmode.YResolution);
  173.   }
  174.   getch ();
  175. }
  176.  
  177.  
  178. void do_rectangles (void)
  179. {
  180.   while (!kbhit ())              /* Random rectangles */
  181.   {
  182.     wsetcolor (rand () % 256);
  183.     wvesa_rectangle (rand () % VESAmode.XResolution, rand () % VESAmode.YResolution,
  184.              rand () % VESAmode.XResolution, rand () % VESAmode.YResolution);
  185.   }
  186.   getch ();
  187. }
  188.  
  189.  
  190. void do_text (void)
  191. {
  192.   wtexttransparent (TEXTFGBG);
  193.   wtextbackground (0);
  194.   while (!kbhit ())              /* Random rectangles */
  195.   {
  196.     wtextcolor (rand () % 256);
  197.     wvesa_outtextxy (rand () % VESAmode.XResolution, rand () % VESAmode.YResolution, 
  198.              NULL, "VESA Text String");
  199.   }
  200.   getch ();
  201. }
  202.  
  203.  
  204. void do_blocks (void)
  205. {
  206.   while (!kbhit ())              /* Randomly paste blocks */
  207.   {
  208.     if (ptr == wgt)             /* Alternate between block 1 and block 2 */
  209.       ptr = wgt2;
  210.     else ptr = wgt;
  211.     wvesa_putblock (rand () % VESAmode.XResolution, rand () % VESAmode.YResolution, 
  212.             ptr, NORMAL);
  213.   }
  214.   getch ();
  215. }
  216.  
  217.  
  218. void main (void)
  219. {
  220.   int oldmode;                  /* Video mode before program was started */
  221.   int mymode = 0;               /* Selected video mode */
  222.  
  223.   oldmode = wgetmode ();        /* Preserve our original video mode */
  224.   _clearscreen (_GCLEARSCREEN); /* Clear the screen */
  225.   if (wvesa_detected ())        /* Look for VESA driver */
  226.     printf ("SVGA detected.\n");
  227.   else
  228.   {
  229.     printf ("SVGA support not found. Please check for VESA driver presence.\n");
  230.     exit (1);
  231.   }
  232.  
  233.   /* Display the video card maunfacturer's string */
  234.   printf ("VESA version %x\n", VGA.VESAVersion);
  235.   printf ("VIDEO CARD OEM STRING:\n%s\n", VGA.OEMStringPtr);
  236.   if (VGA.VESAVersion >= 0x200)
  237.   {
  238.     printf ("OEM Software revision #%x\n", VGA.OemSoftwareRev);
  239.     printf ("OEM Vendor Name: %s\n", VGA.OemVendorNamePtr);
  240.     printf ("OEM Product Name: %s\n", VGA.OemProductNamePtr);
  241.     printf ("OEM Product Revision: %s\n", VGA.OemProductRevPtr);
  242.   }
  243.     else printf ("\n\n\n\n");
  244.  
  245.   printf ("Memory on card: %dk\n", VGA.TotalMemory * 64);
  246.  
  247.   getmodes ();                           /* Find supported video modes */
  248.  
  249.   if (totalmodes == 0)
  250.   {
  251.     printf ("256 color SVGA modes not supported. Program aborted.\n");
  252.     exit (1);
  253.   }
  254.   else
  255.   {
  256.     mymode = select_mode ();
  257.   }    
  258.  
  259.   if (!wvesa_getmodeinfo (mymode))
  260.     printf ("Mode detection failed.\n");
  261.   else
  262.   {
  263.     printf ("\nMode %x selected.\n\n", mymode);
  264.     printf ("X resolution : %5d\nY resolution : %5d\n", VESAmode.XResolution, VESAmode.YResolution);
  265.     printf ("Banks: %d\n", VESAmode.NumberOfBanks);
  266.     printf ("Window Granularity : %d\n", VESAmode.WinGranularity);
  267.     printf ("Window size in Kb  : %d\n", VESAmode.WinSize);
  268.     if (VESAmode.WinAAttributes & 1 == 0)
  269.       printf("Window A not supported\n");
  270.     else
  271.       printf("Window A Segment   : %x\n", VESAmode.WinASegment);
  272.     if (VESAmode.WinBAttributes & 1 == 0)
  273.       printf("Window B not supported\n");
  274.     else
  275.       printf("Window B Segment   : %x\n", VESAmode.WinBSegment);
  276.   }
  277.  
  278.   printf ("\n\nPRESS ANY KEY TO ENTER GRAPHICS MODE\n");
  279.   getch ();
  280.  
  281.   vga256 ();
  282.   if (!wvesa_init (mymode))
  283.   {
  284.     printf ("Unable to initialize graphics mode.\n");
  285.     exit (1);
  286.   }
  287.  
  288.   wgt = wloadpcx ("wgt1.pcx", pal);         /* Load our images */
  289.   wgt2 = wloadpcx ("wgt2.pcx", pal);
  290.   wsetpalette (0, 255, pal);
  291.  
  292.   do_pixels ();                         /* Perform our demo */
  293.   wvesa_cls (15);
  294.   do_blocks ();
  295.   do_lines ();
  296.   do_bars ();
  297.   do_rectangles ();
  298.   do_text ();
  299.   wfreeblock (wgt);                     /* Free the images */
  300.   wfreeblock (wgt2);
  301.   
  302.   wsetmode (oldmode);                    /* Return text mode */
  303. }
  304.  
  305.